package com.apes.scm.rcl.model;

import com.apes.framework.jpa.DefaultPersistListener;
import com.apes.framework.jpa.Model;
import com.apes.framework.jpa.comment.Comment;
import com.apes.framework.jpa.generator.ApesGenerator;
import com.apes.scm.masterdata.enumeration.model.Enumeration;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.SelectBeforeUpdate;

import javax.persistence.*;

/**
 * 功能：日结任务
 *
 * @author xul
 * @create 2019-12-04 15:40
 */
@Getter
@Setter
@SelectBeforeUpdate
@DynamicInsert
@DynamicUpdate
@Entity
@EntityListeners(DefaultPersistListener.class)
@Table(name = RclTask.CONST_TABLE_NAME)
public class RclTask extends Model {
    public static final String CONST_TABLE_NAME = "ir_rcl_task";

    @Id
    @Column(name = "id", nullable = false, length = 30)
    @ApesGenerator(code = CONST_TABLE_NAME, name = "日结任务")
    private String id;

    @Column(name = "name", nullable = false, length = 200)
    @Comment("任务描述")
    private String name;

    @Column(name = "sequence")
    @Comment("序号")
    private int sequence;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "task_type_id", referencedColumnName = "id", nullable = false)
    @Comment("任务类型")
    private Enumeration taskType;

    @Column(name = "actuator", nullable = false, length = 1000)
    @Comment("任务执行器")
    private String actuator;

    @ManyToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
    @JoinColumn(name = "parent_id", unique = true)
    @Comment("上级任务")
    private RclTask parent;

    @Column(name = "started", nullable = false, columnDefinition = "number(1,0) default 0")
    @Comment("开始任务")
    private boolean started = false;

    @Column(name = "finish", nullable = false, columnDefinition = "number(1,0) default 0")
    @Comment("结束任务")
    private boolean finish = false;

    @Column(name = "valid", nullable = false, columnDefinition = "number(1,0) default 1")
    @Comment("是否有效")
    private boolean valid = true;

}
